<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>Vue Router Template Page</title>
</head>
<body>

<div id="root">
    <h2>{{title}}</h2>
    <p>
        <!-- 使用 router-link 组件来导航. -->
        <!-- 通过传入 `to` 属性指定链接. -->
        <!-- <router-link> 默认会被渲染成一个 `<a>` 标签 -->
        <router-link to="/home">Go to Home Page</router-link>
        <router-link to="/about">Go to About Page</router-link>
    </p>
    <!-- 路由出口 -->
    <!-- 路由匹配到的组件将渲染在这里 -->
    <router-view></router-view>
</div>

<script src="../cdn/vue/vue.min.js"></script>
<script src="../cdn/vue/vue-router.js"></script>

<script>

    // 1. 定义 (路由) 组件。
    const Home = {
        template: `
        <div>
            tpl-page-Home
        </div>
    `
    }
    const About = {
        template: `
        <div>
            tpl-page-About
        </div>
    `
    }

    // 2. 定义路由
    const routes = [
        {path: '/home', component: Home},
        {path: '/about', component: About}
    ]

    const router = new VueRouter({
        routes // (缩写) 相当于 routes: routes
    })

    new Vue({
        el: "#root",
        router,
        data() {
            return {title: "Hello Vue..."}
        },
        mounted() {
            console.log("vue app mounted...");
        }
    })

</script>
</body>
</html>
